package com.sokal.easycare.modules.sys.utils;

import org.springframework.stereotype.Component;

import com.sokal.easycare.modules.sys.entity.MainUser;
import com.sokal.easycare.modules.sys.security.SystemAuthorizingRealm.Principal;

/**
 * 用户工具类
 * 
 * @author easycare
 * @version 2017-12-05
 */
@Component("currentUserUtils")
public class CurrentUserUtilsImp implements CurrentUserUtils {

	public MainUser getUser() {
		Principal principal = UserUtils.getPrincipal();
		if (principal != null) {
			MainUser mainUser = UserUtils.get(principal.getId());
			if (mainUser != null) {
				return mainUser;
			}
			return new MainUser();
		}
		// 如果没有登录，则返回实例化空的User对象。
		return new MainUser();

	}

}
